package com.example.voiceassistant.tts;

import com.example.voiceassistant.config.ConfigManager;
import com.example.voiceassistant.monitoring.MonitoringService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 语音合成引擎的演示实现，通过日志模拟播放。
 */
public class TtsEngine {

    private static final Logger LOGGER = LoggerFactory.getLogger(TtsEngine.class);

    private final MonitoringService monitoringService;
    private final ExecutorService executorService = Executors.newSingleThreadExecutor();

    public TtsEngine(ConfigManager configManager, MonitoringService monitoringService) {
        this.monitoringService = monitoringService;
        configManager.findProperty("tts.voice").ifPresent(voice -> LOGGER.info("TTS 将使用音色: {}", voice));
    }

    public void speak(String text) {
        monitoringService.counter("tts.request.count").increment();
        executorService.submit(() -> LOGGER.info("TTS 播报: {}", text));
    }

    public void shutdown() {
        executorService.shutdownNow();
    }
}

